package com.im.service.domain.vo;

import cn.hutool.core.util.ObjUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

/**
 * @author liuzhiqiang
 */
@Data
@ApiModel(value = "ChatVO", description = "ChatVO")
public class ChatVO {

    @ApiModelProperty("id")
    private Long id;

    @ApiModelProperty("是否置顶 true false")
    private Boolean topping;

    @ApiModelProperty("用户id")
    private Long userId;

    @ApiModelProperty("类型 1 人 2 群组")
    private Integer type;

    @ApiModelProperty("目标id 人id 或 群组id")
    private Long targetId;

    @ApiModelProperty("昵称")
    private String nickname;

    @ApiModelProperty("头像")
    private String avatar;

    @ApiModelProperty("在线离线状态")
    private String status;

    @ApiModelProperty("最后的一条消息")
    private String lastMessage;

    @ApiModelProperty("最后一条消息时间")
    private LocalDateTime lastTime;

    @ApiModelProperty("最后一条消息时间戳")
    private Long lastTimeStamp;

    @ApiModelProperty("未读数量")
    private Integer unreadQuantity;

    public Long getLastTimeStamp() {
        if (ObjUtil.isNotNull(lastTime)) {
            ZonedDateTime zonedDateTime = lastTime.atZone(ZoneId.of("Asia/Shanghai"));
            Instant instant = zonedDateTime.toInstant();
            return instant.toEpochMilli();
        }
        return 0L;
    }
}
